package com.comparable_comparator.arraylist;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

class Employee1{
	int id;
	String name;
	int age;
	Employee1(int id,String name,int age){
		this.id=id;
//		this.name=name;
//		this.age=age;
	}
	public String toString(){
		return id+"\t"+name+"\t"+age;
	}

	
	
}
class SortByName implements Comparator{
	public int compare(Object obj1, Object obj2) {
		Employee1 e1=(Employee1)obj1;
		Employee1 e2=(Employee1)obj2;
		String s1=e1.name;
		String s2=e2.name;
		return s2.compareTo(s1);
	}
}
public class EmployeeTest2 {
public static void main(String[] args) {
	Employee1 e1=new Employee1(103, "shashi", 23);
	Employee1 e2=new Employee1(101, "ravi", 25);
	Employee1 e5=new Employee1(101, "ravi", 25);
	Employee1 e3=new Employee1(102, "avinash", 22);
	Employee1 e4=new Employee1(104, "hareram", 28);
	
	ArrayList<Employee1> al1=new ArrayList<Employee1>();
	al1.add(e1);
	al1.add(e2);
	al1.add(e3);
	al1.add(e4);
	al1.add(e5);
	Collections.sort(al1,new SortByName());
	System.out.println(al1);
	for(Employee1 o:al1){
		System.out.println(o);
	}
}
}
